package com.game.events
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	public class GameEventDispatcher extends EventDispatcher
	{
		public function GameEventDispatcher(target : IEventDispatcher = null)
		{
			super(target);

			if (instance != null)
			{
				throw new Error("单例模式不能多次初始化s");
			}
		}

		private static var instance : GameEventDispatcher;

		public static function getInstance() : GameEventDispatcher
		{
			if (instance == null)
			{
				instance = new GameEventDispatcher();
			}

			return instance;
		}

		public function sendNotification(type : String, body : * = null) : Boolean
		{
			var gameEvent : GameEvent = new GameEvent(type, body);
			return dispatchEvent(gameEvent);
		}

		public static function sendNotification(type : String, body : *) : void
		{
			var gameEvent : GameEvent = new GameEvent(type, body);
			instance.dispatchEvent(gameEvent);
		}

		public static function sendError(... args) : void
		{
			sendNotification(GameEventType.ERROR, args);
		}
	}
}